<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>注册</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<link rel="stylesheet" href="http://wx.bjysjglasses.com/ek/css/common/common.css" />
	<link rel="stylesheet" href="http://wx.bjysjglasses.com/ek/css/common/layui.css" />
	<link rel="stylesheet" href="http://wx.bjysjglasses.com/ek/css/common/layer.css" />
	<link rel="stylesheet" href="http://wx.bjysjglasses.com/ek/css/common/header.css" />
	<link rel="stylesheet" href="http://wx.bjysjglasses.com/ek/css/login.css" />

</head>

<body>
	<div id="container">
		<div class="toptop">
			<!-- 头部 -->
			<header>
				<a href="javascript:;" onclick="javascript:history.back(-1);"><img class="back" src="http://wx.bjysjglasses.com/ek/images/jt_zuo.png" /></a>
				<p class="title">注册</p>
			</header>
		</div>
		<form class="content">
			<input type="text" placeholder="请输入手机号" id="tel">
			<input type="password" placeholder="设置6到20位登录密码" id="psd">
			<input type="password" placeholder="请再次输入登录密码" id="yzm">
			<p class="info">已阅读并同意<a href="javascript:;">《用户服务协议》</a></p>
			<li class="btn">
				<p>注册</p>
			</li>
		</form>
	</div>
	<script type="text/javascript" src="http://wx.bjysjglasses.com/ek/js/common/jquery-3.3.1.min.js"></script>
	<script type="text/javascript" src="http://wx.bjysjglasses.com/ek/js/common/common.js"></script>
	<script type="text/javascript" src="http://wx.bjysjglasses.com/ek/js/common/layer.js"></script>
	<script>
		var typeId = localStorage.getItem('typeId');
		$(".btn").click(function () {
			var $optistmobile = $.trim($("#tel").val());
			var $password = $("#psd").val();
			var $messigeCode = $("#yzm").val();
			var isMobile = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
			if (!$optistmobile) {
				layer.msg('请输入手机号码，不能为空');
				return false;
			} else if (!isMobile.test($optistmobile)) {
				layer.msg('请输入有效的手机号码');
				return false;
			}
			if ($password.length < 6) {
				layer.msg('密码不能少于6位');
				return false;
			}
			if ($password != $messigeCode) {
				layer.msg('请确认两次密码一致');
				return false;
			}
			$.ajax({
				type: "post",
				url: global + "/login/publicRegister",
				data: {
					"iphone": $optistmobile,
					"password": $password,
					"type": typeId, //需获取  先写死
				},
				success: function (data) {
					if (data.code == 200) {
						console.log(data.data);
						var res = data.data;
						localStorage.setItem('userId', res.id);
						localStorage.setItem('tokenKey', res.tokenKey);
						layer.msg('注册成功！');
						switch (typeId) {
							case '1':
								localStorage.setItem('tokenKey1', res.tokenKey);
								location.href = "http://wx.bjysjglasses.com/ek/html/shop_enter.html";
								break;
							case '3':
								localStorage.setItem('tokenKey3', res.tokenKey);
								location.href = "http://wx.bjysjglasses.com/ek/html/optometrist_enter.html";
								break;
						}
					} else {
						layer.alert(data.msg);
						location.href = '.http://wx.bjysjglasses.com/ek/html/login.html';
					}
				}
			});
		})
	</script>
</body>

</html>